package com.tuanzi.loan.web.bean.channel;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.common.CommProductIdService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.channel.CommProductIdRequest;
import com.tuanzi.loan.vo.response.channel.CommProductIdResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.channel.CommProductIdLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.LARGE_COMMON_PRODUCT;

/**
 * @author caiwanlin
 * @create 2018-10-18 14:34
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class CommProductIdListBean  extends JSFListingSessionBean<CommProductIdRequest,CommProductIdResponse> {
    @Autowired
    private CommProductIdService commProductIdService;

    @Override
    protected String page() {
        return "/views/channel/product/list.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new CommProductIdRequest();
        lazyDataModel = new CommProductIdLazyDataModel($, session, commProductIdService);
    }

    public void onReset() throws Exception{
        initLazyDataModel();
    }

    public String onAdd(){
        return redirect("/views/channel/product/info.xhtml");
    }

    public String onSee(Long id){
        return redirect("/views/channel/product/info.xhtml?id="+id);
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(LARGE_COMMON_PRODUCT);
    }
}
